package com.atguigu.eduservice.api;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "首页展示")
@RestController
@RequestMapping("/eduservice/index")
@CrossOrigin
public class IndexController {

    @Resource
    private EduCourseService eduCourseService;
    @Resource
    private EduTeacherService eduTeacherService;

    @ApiOperation(value = "首页展示课程信息、讲师信息")
    @GetMapping("getCourseTeacherList")
    public R getCourseTeacherList(){
        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("gmt_create");
        courseWrapper.last("LIMIT 8");
        List<EduCourse> courseList = eduCourseService.list(courseWrapper);
        //讲师信息
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("gmt_create");
        teacherWrapper.last("LIMIT 4");
        List<EduTeacher> teacherList = eduTeacherService.list(teacherWrapper);
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
